/// Index controller
/// ----------------------------------------------------
/// @Project :   xinhou-rocket-admin
/// @File    :   index_controller.rs
/// @Contact :   sp_hrz@qq.com
/// 
/// @Modify Time      @Author    @Version    @Description
/// ------------      -------    --------    -----------
/// 2024/07/04 17:43   shenpeng   1.0         None

use rocket::get;
use rocket::serde::json::Json;
use rocket_okapi::openapi;
use crate::extends::core::initialize::banner_tools::BannerTool;
use crate::extends::core::response::reponse_data::R;

#[openapi(tag = "首页管理")]
#[get("/admin/index/index")]
pub fn index_index() -> Json<R<String>> {
    R::success(Some("Hello word!".parse().unwrap()))
}

#[openapi(tag = "首页管理")]
#[post("/admin/index/banner")]
pub fn index_banner() -> Json<R<String>> {
    let project_name = "xinhou-rocket-admin";
    let banner = BannerTool::generate_banner(project_name);
    match BannerTool::write_banner_to_file(&banner, "banner.txt") {
        Ok(_) => log::info!("Banner generated successfully!"),
        Err(e) => log::error!("Failed to write banner to file: {}", e),
    }

    R::success(Some("Banner generated successfully!".parse().unwrap()))

}
